<?php defined('SYSPATH') or die('No direct script access.');

/**
 * @file city.php
 * @brief 
 * @author Lionel Tsai
 * @version 1.0
 * @date 2012-07-25
 */

define('CITY_CUSGET', 0);
class Model_City extends ORM {

	protected $_table_name = 'terms';
	protected $_primary_key = 'term_id';
	protected $_has_many = array(
		'types' => array('model' => 'type', 'foreign_key' => 'term_id')
	);


	function as_array($type = CITY_CUSGET) {
	 $ret = array();
	 switch($type) {
	 case CITY_CUSGET:
		//$ret = parent::as_array();
		$ret['city_id'] = $this->term_id;
		$ret['city_name'] = $this->name;

		$pinyin = new Tool_Pinyinparse();
		$ret['city_slug'] = $pinyin->Pinyin($this->name, 'UTF-8');
		break;
	 default:
		$ret = parent::as_array();
		//get pinyin
		$pinyin = new Tool_Pinyinparse();
	    $ret['term_pinyin'] = $pinyin->Pinyin($this->name, 'UTF-8');
		break;	
	 }
	 return $ret;
	}
}
